<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>修改密码</title>
    <!-- Font Awesome Icons -->
    <link rel="stylesheet" href="../../../../plugins/fontawesome-free/css/all.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../../../../dist/css/adminlte.min.css">
    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet" href="../../../../plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css">
    <link href="../../../../dist/css/fonts.css" rel="stylesheet">
</head>

<body class="hold-transition sidebar-mini">
    <div class="wrapper">
        <!-- Navbar -->
        <nav class="main-header navbar navbar-expand navbar-white navbar-light" id="navbar_menu">
            <!-- Left navbar links -->
        </nav>
        <!-- /.navbar -->
        <!-- Main Sidebar Container -->
        <aside class="main-sidebar sidebar-dark-primary elevation-4" id="sidebar_menu">
        </aside>
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <section class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1>修改密码</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="#">主页</a></li>
                            </ol>
                        </div>
                    </div>
                </div><!-- /.container-fluid -->
            </section>
            <div class="content">
                <div class="container-fluid">
                    <div class="row">
                        <!-- left column -->
                        <div class="col-md-12">
                            <!-- jquery validation -->
                            <div class="card card-primary">
                                <div class="card-header">
                                    <h3 class="card-title">用户修改密码</h3>
                                </div>
                                <!-- /.card-header -->
                                <!-- form start -->
                                <form>
                                    <div class="card-body">
                                        <div class="form-group">
                                            <label for="oldPassword">原密码</label>
                                            <input type="password" name="oldPassword" class="form-control"
                                                id="oldPassword" placeholder="请填写原密码">
                                        </div>
                                        <div class="form-group">
                                            <label for="newPassword_0">新密码</label>
                                            <input type="password" name="newPassword_0" class="form-control"
                                                id="newPassword_0" placeholder="请填写新密码">
                                        </div>
                                        <div class="form-group">
                                            <label for="newPassword_1">确认</label>
                                            <input type="password" name="newPassword_1" class="form-control"
                                                id="newPassword_1" placeholder="请确认密码">
                                        </div>

                                    </div>
                                    <!-- /.card-body -->

                                </form>
                                <div class="card-footer">
                                    <button id="submit_btn" class="btn btn-primary">提交</button>
                                </div>
                            </div>
                            <!-- /.card -->
                        </div>
                        <!--/.col (left) -->
                        <!-- right column -->
                        <div class="col-md-6">

                        </div>
                        <!--/.col (right) -->
                    </div>
                    <!-- /.row -->
                </div><!-- /.container-fluid -->
            </div>
            <!-- /.content -->
        </div>
    </div>
    <!-- /.content-wrapper -->
    </div>
    <!-- ./wrapper -->
    <!-- REQUIRED SCRIPTS -->
    <!-- jQuery -->
    <script src="../../../../plugins/sweetalert2/sweetalert2.min.js"></script>
    <script src="../../../../plugins/jquery/jquery.min.js"></script>
    <script>
        // 引入左边导航栏
        $.get("../../../../bars/Operator/operator_sidebar.html", function (data) {
            // console.log(data)
            $("#sidebar_menu").html(data);
        })
        //引入上边导航栏 
        $.get("../../../../bars/Operator/operator_navbar.html", function (data) {
            $("#navbar_menu").html(data);
        })
    </script>

    <!-- Bootstrap 4 -->
    <script src="../../../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../../../../plugins/sweetalert2/sweetalert2.min.js"></script>
    <script src="../../../../dist/js/adminlte.min.js"></script>
    <script>
        const Toast = Swal.mixin({
            toast: true,
            showConfirmButton: false,
            timer: 1500
        });
        $("#submit_btn").on("click", function () {
            console.log()
            if ($("#oldPassword").val()=="") {
                Toast.fire({
                    icon: 'error',
                    title: ' 原密码不能为空'
                })
                return false
            } else if ($("#newPassword_0").val() == "") {
                Toast.fire({
                    icon: 'error',
                    title: ' 新密码不能为空'
                })
                return false
            } else if ($("#newPassword_1").val() == "") {
                Toast.fire({
                    icon: 'error',
                    title: ' 新密码不能为空'
                })
                return false
            } else {
                if ($("#newPassword_0").val() != $("#newPassword_1").val()) {
                    Toast.fire({
                        icon: 'error',
                        title: ' 两次输入的密码不一致'
                    })
                } else {
                    $.ajax(
                        {
                            type: 'POST',
                            url: "/operator/changePassword",
                            async: true,
                            dataType: 'Text',
                            crossDomain: true,
                            xhrFields: {
                                withCredentials: true
                            },
                            data: {
                                password: $("#oldPassword").val(),
                                newPassword: $("#newPassword_1").val()
                            },
                            contentType: "application/x-www-form-urlencoded",
                            success: function (res) {
                                console.log(JSON.parse(res))



                                if (JSON.parse(res).statusCode === "200") {
                                    Toast.fire({
                                        icon: 'success',
                                        title: ' 修改成功'
                                    })
                                    setTimeout(function () { window.location.href = "/member/login" }, 1000);
                                    return false
                                } else {
                                    Toast.fire({
                                        icon: 'error',
                                        title: ' 密码错误'
                                    })
                                    return false
                                }
                            },
                            error: function (err) {
                                Toast.fire({
                                    icon: 'error',
                                    title: ' 请重试'
                                })
                            }
                        })
                }
            }



        })

    </script>
</body>

</html>